package GUI;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.border.LineBorder;
import java.awt.Color;
import javax.swing.table.DefaultTableModel;
import javax.swing.JList;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.SwingConstants;

public class Cycle extends JFrame implements ActionListener{

	private JPanel contentPane;
	private JTable table;
	private JTable table_1;
	private JTable tableInstructionStatus;
	private JLabel lblInstruction;
	private JLabel lblReservationStationStatus;
	private JLabel lblBuffers;
	private JLabel lblCycle;
	private JLabel lblCache;
	JLabel lblNewLabel;
	JButton btnNext;
	int number;
	int reservationStations;
	ProgramAndData pnd;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Cycle frame = new Cycle(0,10,null);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
//	public Cycle() {
//		setTitle("Cycle by cycle");
//		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//		
//		setBounds(100, 100, 829, 620);
//		contentPane = new JPanel();
//		contentPane.setBorder(new LineBorder(new Color(0, 0, 0), 2));
//		setContentPane(contentPane);
//		
//		table = new JTable();
//		table.setBounds(24, 200, 727, 161);
//		table.setGridColor(Color.DARK_GRAY);
//		table.setFillsViewportHeight(true);
//		table.setBorder(new LineBorder(new Color(0, 0, 0)));
//		table.setModel(new DefaultTableModel(
//			new Object[][] {
//				{"Resv Station", "Busy", "Op", "Vj", "Vk", "Qj", "Qk"},
//				{null, null, null, null, null, null, null},
//				{null, null, null, null, null, null, null},
//			},
//			new String[] {
//				"Reservation Station", "Busy", "Op", "Vj", "Vk", "Qj", "Qk"
//			}
//		) {
//			Class[] columnTypes = new Class[] {
//				String.class, String.class, String.class, String.class, String.class, String.class, String.class
//			};
//			public Class getColumnClass(int columnIndex) {
//				return columnTypes[columnIndex];
//			}
//		});
//		table.getColumnModel().getColumn(0).setPreferredWidth(107);
//		table.getColumnModel().getColumn(1).setPreferredWidth(62);
//		table.getColumnModel().getColumn(2).setPreferredWidth(97);
//		table.getColumnModel().getColumn(3).setPreferredWidth(59);
//		table.getColumnModel().getColumn(4).setPreferredWidth(58);
//		table.getColumnModel().getColumn(5).setPreferredWidth(61);
//		table.getColumnModel().getColumn(6).setPreferredWidth(61);
//		contentPane.setLayout(null);
//		
//		tableInstructionStatus = new JTable();
//		tableInstructionStatus.setBorder(new LineBorder(new Color(0, 0, 0)));
//		tableInstructionStatus.setBounds(24, 36, 324, 128);
//		tableInstructionStatus.setModel(new DefaultTableModel(
//			new Object[][] {
//				{"Instruction", "Issue", "Execute", "Write"},
//				{null, null, null, null},
//			},
//			new String[] {
//				"Instruction", "Issue", "Execute", "Write"
//			}
//		));
//		tableInstructionStatus.getColumnModel().getColumn(0).setPreferredWidth(157);
//		contentPane.add(tableInstructionStatus);
//		contentPane.add(table);
//		
//		table_1 = new JTable();
//		table_1.setBorder(new LineBorder(new Color(0, 0, 0)));
//		table_1.setModel(new DefaultTableModel(
//			new Object[][] {
//				{"Name", "Busy", "Address"},
//				{null, null, null},
//			},
//			new String[] {
//				"Name", "Busy", "Address"
//			}
//		));
//		table_1.getColumnModel().getColumn(0).setPreferredWidth(83);
//		table_1.setBounds(560, 36, 222, 137);
//		contentPane.add(table_1);
//		
//		lblInstruction = new JLabel("Instruction Status");
//		lblInstruction.setBounds(24, 11, 112, 14);
//		contentPane.add(lblInstruction);
//		
//		lblReservationStationStatus = new JLabel("Reservation Station Status");
//		lblReservationStationStatus.setBounds(24, 175, 239, 14);
//		contentPane.add(lblReservationStationStatus);
//		
//		lblBuffers = new JLabel("Buffers");
//		lblBuffers.setBounds(560, 11, 95, 14);
//		contentPane.add(lblBuffers);
//		
//		lblCycle = new JLabel("Cycle");
//		lblCycle.setFont(new Font("Tahoma", Font.BOLD, 14));
//		lblCycle.setBounds(404, 11, 85, 14);
//		contentPane.add(lblCycle);
//		
//		JButton btnNext = new JButton("Next");
//		btnNext.setBounds(714, 550, 89, 23);
//		contentPane.add(btnNext);
//		
//		lblCache = new JLabel("Cache");
//		lblCache.setBounds(24, 372, 85, 14);
//		contentPane.add(lblCache);
//		
//		JLabel lblNumber = new JLabel("");
//		lblNumber.setHorizontalAlignment(SwingConstants.CENTER);
//		lblNumber.setFont(new Font("Tahoma", Font.PLAIN, 14));
//		lblNumber.setBackground(Color.WHITE);
//		lblNumber.setBounds(404, 46, 42, 23);
//		contentPane.add(lblNumber);
//		
//		this.setVisible(true);
//	}
	public Cycle(int number, int reservation,ProgramAndData p)
	{
		this.number = number ;
		reservationStations = reservation;
		pnd=p;
		setTitle("Cycle by cycle");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		setBounds(100, 100, 829, 620);
		contentPane = new JPanel();
		contentPane.setBorder(new LineBorder(new Color(0, 0, 0), 2));
		setContentPane(contentPane);
		
		table = new JTable();
		table.setBounds(24, 200, 727, 161);
		table.setGridColor(Color.DARK_GRAY);
		table.setFillsViewportHeight(true);
		table.setBorder(new LineBorder(new Color(0, 0, 0)));
		table.setModel(new DefaultTableModel(
			new Object[][] {
				{"Resv Station", "Busy", "Op", "Vj", "Vk", "Qj", "Qk"},
				{null, null, null, null, null, null, null},
				{null, null, null, null, null, null, null},
			},
			new String[] {
				"Reservation Station", "Busy", "Op", "Vj", "Vk", "Qj", "Qk"
			}
		) {
			Class[] columnTypes = new Class[] {
				String.class, String.class, String.class, String.class, String.class, String.class, String.class
			};
			public Class getColumnClass(int columnIndex) {
				return columnTypes[columnIndex];
			}
		});
		table.getColumnModel().getColumn(0).setPreferredWidth(107);
		table.getColumnModel().getColumn(1).setPreferredWidth(62);
		table.getColumnModel().getColumn(2).setPreferredWidth(97);
		table.getColumnModel().getColumn(3).setPreferredWidth(59);
		table.getColumnModel().getColumn(4).setPreferredWidth(58);
		table.getColumnModel().getColumn(5).setPreferredWidth(61);
		table.getColumnModel().getColumn(6).setPreferredWidth(61);
		contentPane.setLayout(null);
		
		tableInstructionStatus = new JTable();
		tableInstructionStatus.setBorder(new LineBorder(new Color(0, 0, 0)));
		tableInstructionStatus.setBounds(24, 36, 324, 128);
		tableInstructionStatus.setModel(new DefaultTableModel(
			new Object[][] {
				{"Instruction", "Issue", "Execute", "Write"},
				{null, null, null, null},
			},
			new String[] {
				"Instruction", "Issue", "Execute", "Write"
			}
		));
		tableInstructionStatus.getColumnModel().getColumn(0).setPreferredWidth(157);
		contentPane.add(tableInstructionStatus);
		contentPane.add(table);
		
		table_1 = new JTable();
		table_1.setBorder(new LineBorder(new Color(0, 0, 0)));
		table_1.setModel(new DefaultTableModel(
			new Object[][] {
				{"Name", "Busy", "Address"},
				{null, null, null},
			},
			new String[] {
				"Name", "Busy", "Address"
			}
		));
		table_1.getColumnModel().getColumn(0).setPreferredWidth(83);
		table_1.setBounds(560, 36, 222, 137);
		contentPane.add(table_1);
		
		lblInstruction = new JLabel("Instruction Status");
		lblInstruction.setBounds(24, 11, 112, 14);
		contentPane.add(lblInstruction);
		
		lblReservationStationStatus = new JLabel("Reservation Station Status");
		lblReservationStationStatus.setBounds(24, 175, 239, 14);
		contentPane.add(lblReservationStationStatus);
		
		lblBuffers = new JLabel("Buffers");
		lblBuffers.setBounds(560, 11, 95, 14);
		contentPane.add(lblBuffers);
		
		lblCycle = new JLabel("Cycle");
		lblCycle.setFont(new Font("Tahoma", Font.BOLD, 14));
		lblCycle.setBounds(404, 11, 85, 14);
		contentPane.add(lblCycle);
		
		btnNext = new JButton("Next");
		btnNext.setBounds(714, 550, 89, 23);
		btnNext.addActionListener(this);
		contentPane.add(btnNext);
		
		lblCache = new JLabel("Cache");
		lblCache.setBounds(24, 372, 85, 14);
		contentPane.add(lblCache);
		
		JLabel lblNumber = new JLabel(""+number);
		lblNumber.setHorizontalAlignment(SwingConstants.CENTER);
		lblNumber.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblNumber.setBackground(Color.WHITE);
		lblNumber.setBounds(404, 46, 42, 23);
		contentPane.add(lblNumber);
		
		this.setVisible(true);
	}
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==btnNext)
		{
			this.dispose();
			new Cycle(++number,reservationStations,pnd);
		}
	}
}
